<?php
class MagicuseraddnumberAction extends CommonAction {
	function index(){
		$this->listmap="1 and m.site_id=".$this->siteid;
		$this->magic = M('Magic') -> where(array('id' => $this->_get('magic_id'))) -> find();
        parent::_list("n","left join __MEMBER__ as m on m.id=n.aid","m.username, m.openid, n.*");
		$this->display();
	}
	function delete(){
		if($this->_get('aid') && $this->_get('magic_id')){
		    $map['aid'] = $this->_get('aid');
			$map['magic_id'] = $this->_get('magic_id');
			$re = $this->dao->where($map)->delete();
			if($re !== false){
				$this->success('删除成功');
			}else{
			    $this->error($this->dao->getError());
			}
		}else{
			$this->error('参数错误');
		}
	}
	public function add(){
		$this->listmap="1";
		$this->listmap.=" and m.site_id=".$this->siteid;
		$this->magic = M('Magic') -> where(array('id' => $this->_get('magic_id'))) -> find();
		$this->dao = D('Member');
        parent::_list("m","left join __MEMBER_GROUP__ as g on m.group_id=g.id","m.*,g.title as groupname");
		$this->display();
	}
	public function insert(){
		if($this->_post('aid')){
			$data['number'] = $this->_post('number');
			$data['magic_id'] = $this->_post('magic_id');
			$aid = explode(',',$this->_post('aid'));
			foreach($aid as $v){
				$data['aid'] = $v;
				$this->dao->where(array('aid' => $v,'magic_id' => $data['magic_id']))->delete();
				$this->dao->data($data)->add();
			}
			$this->success('添加成功');
		}
	}
}

?>